home *** CD-ROM | disk | FTP | other *** search
- -- 2000.03.12
- -- Clive Green <clivegreen@atlas.co.uk>
-
- ------------------------------------------------------------------------------------------------------
-
- -- miscellaneous stuff:
-
- ------------------------------------------------------------------------------------------------------
-
- -- declare properties:
- property main -- main code directory object
- property pathDelims -- a #propList of platform-specific pathname delimiter symbols
-
- ------------------------------------------------------------------------------------------------------
-
- on new me,L
-
- -- (1) extract and check arguments:
-
- -- check for a parameter list:
- if ilk(L) <> #propList then return [#error:#noParamListSupplied, #msg:"utilityMethods:new"]
-
- -- a reference to the parent codebase is REQUIRED:
- main = L[#main]
- if (ilk(main) <> #instance) then return [#error:#noMainObjectSupplied, #msg:"utilityMethods:new"]
-
- --------------------
-
- -- store a #propList of path delimiters:
- pathDelims = [:]
- pc = "\"
- mac = ":"
- pathDelims[#PC] = [#lookFor:mac, #replaceWith:pc]
- pathDelims[#Mac] = [#lookFor:pc, #replaceWith:mac]
-
- --------------------
-
- -- pass back my address:
- return me
-
- ----------------------------------------------------------------------------------------------------
-
- on listFromText me,t
-
- -- this converts the multiple-line string t into a lingo propList:
-
- -- must have a string!
- if not stringP(t) then return #null
- if not length(t) then return #null
-
- --------------------
-
- -- create an empty container:
- L = [:]
-
- -- recurse over each line:
- repeat with i = 1 to the number of lines of t
-
- x = t.line[i]
-
- -- blank lines are treated as EOF!
- if not length(x) then exit repeat
-
- -- ASSUMPTION: the first word on each line is the property name to be used;
- -- the remainder is the data item to be stored:
- p = x.word[1]
- delete word 1 of x
-
- -- look out for stringised lists and symbols:
- v = value(x)
- if listP(v) or symbolP(v) then x = v
-
- -- assign the value to a named location:
- L[symbol(p)] = x
-
- end repeat
-
- -- pass back to the caller:
- return L
-
- ----------------------------------------------------------------------------------------------------
-
- on parseFilePath me,p
-
- -- parse the filepath string p supplied so it contains platform specific pathname delimiters:
-
- -- a string is required:
- if not stringP(p) then return ¬
- [#error:#noStringSupplied, #msg:"utilityMethods:getPlatFormFilePath"]
-
- if not length(p) then return ¬
- [#error:#emptyString, #msg:"utilityMethods:getPlatFormFilePath"]
-
- --------------------
-
- -- process delimiters according to the runtime platform:
- um = main.getUtilityMethods()
- x = um.thePlatform()
- L = pathDelims[x]
-
- -- in the path p supplied, we need to replace what character with what other character?
- a = L[#lookFor]
- b = L[#replaceWith]
-
- --------------------
-
- -- begin replacing characters from what position?
- z = 1
-
- -- wrinkle:
-
- -- p might begin with something like "D:\" -- in this case, we need to ensure the colon is
- -- preserved when forcing p to a pc filePath (mac paths use a colon as a delimiter!)
- if (p.char[2] = ":") and (x = #PC) then z = 3
-
- --------------------
-
- -- search and replace:
- repeat with i = z to length(p)
-
- if char i of p <> a then next repeat
- put b into char i of p
-
- end repeat
-
- --------------------
-
- -- pass back processed string to the caller:
- return p
-
- ----------------------------------------------------------------------------------------------------
-
- on thePlatform me
-
- -- pass back an identification of the current platform:
- if the platform starts "Win" then return #PC
- else return #Mac
-
- ----------------------------------------------------------------------------------------------------
-
- on printStr me,s
-
- -- attempt to show the feedback message string s:
- sm = main.getServiceManager()
- fb = sm.getService(#feedbackService)
- if (ilk(fb) <> #instance) then return fb
-
- fb.feedbackMsg(s)
-
- ----------------------------------------------------------------------------------------------------